const path = require('path')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const HtmlWebpackPlugin = require("html-webpack-plugin")
const HtmlWebpackTagsPlugin = require('html-webpack-tags-plugin')
const MyPlugin = require('./plugin-loader/my-plugin.js')
module.exports = {
  mode: 'development',
  entry: './src/react.js',
  devtool: 'cheap-module-source-map',
  output: {
    path: path.resolve(__dirname, 'output'),
    filename: 'main.js',
    publicPath: './'
  },
  devServer: {
    port: 7513,
    hot: true
  },
  module: {
    rules: [
      {
        test: /\.jsx?$/,
        use: {
          loader: 'babel-loader'
        }
      },
      {
        test: /\.css$/,
        use: [MiniCssExtractPlugin.loader, 'css-loader']
      },
      {
        test: /\.mobile$/,
        use: [MiniCssExtractPlugin.loader, 'css-loader', {
          loader: './plugin-loader/my-loader.js',
          options: {
            size: 7500
          }
        }]
      }
    ]
  },
  plugins: [
    new MyPlugin(),
    new MiniCssExtractPlugin({
      filename: '[name].css',
      chunkFilename: '[id].css'
    }),
    new HtmlWebpackPlugin({
      template: './index.html',
      filename: 'index.html'
    }),
    new HtmlWebpackTagsPlugin({
      publicPath: '',
      append: false,
      // metas: [
      //   {
      //     attributes: {
      //       'http-equiv': 'version',
      //       content: 'v1.0.0'
      //     }
      //   }
      // ],
      scripts: ['http://frontlog.9tech.cn/js/changeyouErrorHandle.js'],
    }),
    new HtmlWebpackTagsPlugin({
      // tags: ['http://frontlog.9tech.cn/js/changeyouErrorHandle.js','b.css'],
      append: false,
      metas: [
        {
          attributes: {
            'http-equiv': 'version',
            content: 'v1.0.0'
          }
        }
      ],
      // scripts: ['http://frontlog.9tech.cn/js/changeyouErrorHandle.js'],
    })
  ],
  optimization: {
    splitChunks: {
      cacheGroups: {
        vendor: {
          filename: 'vendor.js',
          chunks: 'all',
          test: /[\\/]node_modules[\\/](react|react-dom)[\\/]/
        }
      }
    }
  }
}